package com.tanhua.app.controller;

import com.tanhua.app.service.TestSoulService;
import com.tanhua.model.dto.AnswersDto;
import com.tanhua.model.vo.ReportVo;
import com.tanhua.model.vo.TestSoulVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/testSoul")
public class TestSoulController {

    @Autowired
    private TestSoulService testSoulService;


    @GetMapping
    public ResponseEntity getTestSoul(){
        List<TestSoulVo> list = testSoulService.getTestSoulInfo();
        return ResponseEntity.ok(list);
    }


    @PostMapping
    public ResponseEntity submitAnswer(@RequestBody Map<String,List<AnswersDto>> map){

        List<AnswersDto> answers = map.get("answers");

        String reportId = testSoulService.submitAnswers(answers);
        return ResponseEntity.ok(reportId);
    }

    @GetMapping("/report/{id}")
    public ResponseEntity report(@PathVariable("id") Long id){
        ReportVo vo = testSoulService.report(id);
        return ResponseEntity.ok(vo);
    }
}
